package com.neuedu.helloworld;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.WindowManager;

public class SplashActivity extends AppCompatActivity {


    Handler handler = new Handler(){

        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            SharedPreferences sharedPreferences = getSharedPreferences(LoginActivity.AUTO_LOGIN,MODE_PRIVATE);

            String username = sharedPreferences.getString("username","");
            String password = sharedPreferences.getString("password","");

            Intent intent =  null;
            //登录成功的时候
            if("admin".equals(username) && "123456".equals(password)){
                intent = new Intent(SplashActivity.this, MainActivity.class );
            }else{
                //显示意图
                 intent  = new Intent(SplashActivity.this,   LoginActivity.class);
            }

            startActivity(intent);
            finish();
        }
    };








    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        //设置全屏  信号、电池
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);



        setContentView(R.layout.activity_splash);




    }





    @Override
    protected void onResume() {
        super.onResume();

       new Thread(){

           @Override
           public void run() {
               try {
                   Thread.sleep(500);
                   handler.sendMessage( handler.obtainMessage() );
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
       }.start();


    }
}